/*
ID: guoxu1
PROG: checker
LANG: C++
*/
#include <cstring>
#include <iostream>
#include <fstream>
using namespace std;

const int max_board_side = 13;

#define cin fin
#define cout fout

ifstream fin( "checker.in" );
ofstream fout( "checker.out" );

struct Board
{
	int pos[ max_board_side ];
	unsigned int column;
	unsigned int diagonal1;
	unsigned int diagonal2;
	int side;
	int count;

	Board( int _side ):side( _side )
	{
		memset( pos, 0, sizeof( pos ) );
		column = 0;
		diagonal1 = 0;
		diagonal2 = 0;
		count = 0;
	}

	inline bool test( int r, int c )
	{
		if( ( column & ( 1 << c ) ) != 0 ) return false;
		if( ( diagonal1 & ( 1 << ( r + c ) ) ) != 0 ) return false;
		if( ( diagonal2 & ( 1 << ( r - c + side - 1 ) ) ) != 0 ) return false;
		return true;
	}

	inline void put( int r, int c )
	{
		column |= ( 1 << c );
		diagonal1 |= ( 1 << ( r + c ) );
		diagonal2 |= ( 1 << ( r - c + side - 1 ) );
		pos[ r ] = c;
	}

	inline void unput( int r, int c )
	{
		column &= ~( 1 << c );
		diagonal1 &= ~( 1 << ( r + c ) );
		diagonal2 &= ~( 1 << ( r - c + side - 1 ) );
	}

	void dfs( int n )
	{
		if( n == side )
		{
			count++;
			if( count > 3 ) return;
			for( int i = 0; i < side; i++ )
			{
				if( i != 0 ) cout << " ";
				cout <<pos[ i ] + 1;
			}
			cout << endl;
			return;
		}

		for( int i = 0; i < side; i++ )
		{
			if( test( n, i ) )
			{
				put( n, i );
				dfs( n + 1 );
				unput( n, i );
			}
		}
	}
};

int main()
{
	int n = 0;
	cin >> n;
	Board b( n );
	if( n < 13 ) b.dfs(0);
	else
	{
	  for( int i = 0; i < n / 2; i++ )
	  {
		  b.put( 0, i );
		  b.dfs( 1 );
		  b.unput( 0, i );
	  }
	  b.count *= 2;
	  if( n % 2 != 0 )
	  {
		  b.put( 0, n / 2 );
		  b.dfs( 1 );
		  b.unput( 0, n / 2 );
	  }
  }
	cout << b.count << endl;
	return 0;
}
